/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import actions.facade.FacadeAction;
import com.opensymphony.xwork2.ActionContext;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.FinderException;
import miage.beans.FacturePresentation;
import miage.sessions.ecom.remote.EcomCustomerRemote;

/**
 *
 * @author Pepito
 */
public class HistoriqueAction extends FacadeAction{
    private static EcomCustomerRemote rechercher;
    private List<FacturePresentation> facturePresentation = new ArrayList<FacturePresentation>();
    private Map session = ActionContext.getContext().getSession();
    private String login, password;
    
    public List<FacturePresentation> getFacturePresentation() {
        return facturePresentation;
    }

    public void setFacturePresentation(List<FacturePresentation> facturePresentation) {
        this.facturePresentation = facturePresentation;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    @Override
    public String execute() throws RemoteException, FinderException{
        rechercher = (EcomCustomerRemote) Connexion.ConnexionCustomer.connectionServerBean();
        setLogin(String.valueOf(session.get("login")));
        setPassword(String.valueOf(session.get("password")));
        System.out.println("login : "+login);
        
        try {
            facturePresentation = rechercher.getAllFactureByClient(login);
            return "success";
        }catch (FinderException ex) {
            Logger.getLogger(HistoriqueAction.class.getName()).log(Level.SEVERE, null, ex);
            return "input";
        } catch (RemoteException ex) {
            Logger.getLogger(HistoriqueAction.class.getName()).log(Level.SEVERE, null, ex);
            return "input";
        }     
    }
}
